﻿Imports DotNetNuke

Namespace DotNetNuke.Modules.ActiveForums
    Public Class ForumSettingsBase
        Inherits Entities.Modules.ModuleSettingsBase
        Dim objModules As New Entities.Modules.ModuleController

        Public Property Mode() As String
            Get
                Return GetStringSetting(SettingKeys.Mode, "Standard")
            End Get
            Set(value As String)
                Settings(SettingKeys.Mode) = value
                objModules.UpdateTabModuleSetting(TabModuleId, SettingKeys.Mode, value)
            End Set
        End Property

        Public Property Theme() As String
            Get
                Return GetStringSetting(SettingKeys.Theme, "_default")
            End Get
            Set(value As String)
                Settings(SettingKeys.Theme) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.Theme, value)
            End Set
        End Property

        Public Property TemplateId() As Integer
            Get
                Return GetIntegerSetting(SettingKeys.ForumTemplateId, 0)
            End Get
            Set(value As Integer)
                Settings(SettingKeys.ForumTemplateId) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.ForumTemplateId, value.ToString())
            End Set
        End Property

        Public Property PageSize() As Integer
            Get
                Return GetIntegerSetting(SettingKeys.PageSize, 20)
            End Get
            Set(value As Integer)
                Settings(SettingKeys.PageSize) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.PageSize, value.ToString())
            End Set
        End Property

        Public Property FloodInterval() As Integer
            Get
                Return GetIntegerSetting(SettingKeys.FloodInterval, 0)
            End Get
            Set(value As Integer)
                Settings(SettingKeys.FloodInterval) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.FloodInterval, value.ToString())
            End Set
        End Property

        Public Property EditInterval() As Integer
            Get
                Return GetIntegerSetting(SettingKeys.EditInterval, 0)
            End Get
            Set(value As Integer)
                Settings(SettingKeys.EditInterval) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.EditInterval, value.ToString())
            End Set
        End Property

        Public Property AutoLink() As Boolean
            Get
                Return GetBooleanSetting(SettingKeys.EnableAutoLink, True)
            End Get
            Set(value As Boolean)
                Settings(SettingKeys.EnableAutoLink) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.EnableAutoLink, value.ToString())
            End Set
        End Property

        Public Property DeleteBehavior() As Integer
            Get
                Return GetIntegerSetting(SettingKeys.DeleteBehavior, 0)
            End Get
            Set(value As Integer)
                Settings(SettingKeys.DeleteBehavior) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.DeleteBehavior, value.ToString())
            End Set
        End Property

        Public Property AddThis() As String
            Get
                Return GetStringSetting(SettingKeys.AddThisAccount, String.Empty)
            End Get
            Set(value As String)
                Settings(SettingKeys.AddThisAccount) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.AddThisAccount, value)
            End Set
        End Property

        Public Property ProfileType() As Integer
            Get
                Return GetIntegerSetting(SettingKeys.ProfileType, 1)
            End Get
            Set(value As Integer)
                Settings(SettingKeys.ProfileType) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.ProfileType, value.ToString())
            End Set
        End Property

        Public Property Signatures() As Integer
            Get
                Return GetIntegerSetting(SettingKeys.AllowSignatures, 1)
            End Get
            Set(value As Integer)
                Settings(SettingKeys.AllowSignatures) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.AllowSignatures, value.ToString())
            End Set
        End Property

        Public Property UserNameDisplay() As String
            Get
                Return GetStringSetting(SettingKeys.UserNameDisplay, "Username")
            End Get
            Set(value As String)
                Settings(SettingKeys.UserNameDisplay) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.UserNameDisplay, value)
            End Set
        End Property

        Public Property FriendlyURLs() As Boolean
            Get
                Return GetBooleanSetting(SettingKeys.EnableURLRewriter, False)
            End Get
            Set(value As Boolean)
                Settings(SettingKeys.EnableURLRewriter) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.EnableURLRewriter, value.ToString())
            End Set
        End Property

        Public Property PrefixURLBase() As String
            Get
                Return GetStringSetting(SettingKeys.PrefixURLBase, "forums")
            End Get
            Set(value As String)
                Settings(SettingKeys.PrefixURLBase) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.PrefixURLBase, value)
            End Set
        End Property
        Public Property PrefixURLTag() As String
            Get
                Return GetStringSetting(SettingKeys.PrefixURLTags, "tag")
            End Get
            Set(value As String)
                Settings(SettingKeys.PrefixURLTags) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.PrefixURLTags, value)
            End Set
        End Property

        Public Property PrefixURLCategory() As String
            Get
                Return GetStringSetting(SettingKeys.PrefixURLCategories, "category")
            End Get
            Set(value As String)
                Settings(SettingKeys.PrefixURLCategories) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.PrefixURLCategories, value)
            End Set
        End Property

        Public Property PrefixURLOther() As String
            Get
                Return GetStringSetting(SettingKeys.PrefixURLOther, "views")
            End Get
            Set(value As String)
                Settings(SettingKeys.PrefixURLOther) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.PrefixURLOther, value)
            End Set
        End Property

        Public Property FullTextSearch() As Boolean
            Get
                Return GetBooleanSetting(SettingKeys.FullText, False)
            End Get
            Set(value As Boolean)
                Settings(SettingKeys.FullText) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.FullText, value.ToString())
            End Set
        End Property

        Public Property MailQueue() As Boolean
            Get
                Return GetBooleanSetting(SettingKeys.MailQueue, False)
            End Get
            Set(value As Boolean)
                Settings(SettingKeys.MailQueue) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.MailQueue, value.ToString())
            End Set
        End Property

        Public Property EnablePoints() As Boolean
            Get
                Return GetBooleanSetting(SettingKeys.EnablePoints, False)
            End Get
            Set(value As Boolean)
                Settings(SettingKeys.EnablePoints) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.EnablePoints, value.ToString())
            End Set
        End Property

        Public Property TopicPointValue() As Integer
            Get
                Return GetIntegerSetting(SettingKeys.TopicPointValue, 1)
            End Get
            Set(value As Integer)
                Settings(SettingKeys.TopicPointValue) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.TopicPointValue, value.ToString())
            End Set
        End Property

        Public Property ReplyPointValue() As Integer
            Get
                Return GetIntegerSetting(SettingKeys.ReplyPointValue, 1)
            End Get
            Set(value As Integer)
                Settings(SettingKeys.ReplyPointValue) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.ReplyPointValue, value.ToString())
            End Set
        End Property

        Public Property AnswerPointValue() As Integer
            Get
                Return GetIntegerSetting(SettingKeys.AnswerPointValue, 1)
            End Get
            Set(value As Integer)
                Settings(SettingKeys.AnswerPointValue) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.AnswerPointValue, value.ToString())
            End Set
        End Property

        Public Property MarkAsAnswerPointValue() As Integer
            Get
                Return GetIntegerSetting(SettingKeys.MarkAnswerPointValue, 1)
            End Get
            Set(value As Integer)
                Settings(SettingKeys.MarkAnswerPointValue) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.MarkAnswerPointValue, value.ToString())
            End Set
        End Property

        Public Property ModPointValue() As Integer
            Get
                Return GetIntegerSetting(SettingKeys.ModPointValue, 1)
            End Get
            Set(value As Integer)
                Settings(SettingKeys.ModPointValue) = value
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.ModPointValue, value.ToString())
            End Set
        End Property

        Public Property ForumGroupTemplate() As Integer
            Get
                Return GetIntegerSetting("ForumGroupTemplate", -1)
            End Get
            Set(value As Integer)
                Settings("ForumGroupTemplate") = value
                'Use Tab Module Setting
                objModules.UpdateTabModuleSetting(TabModuleId, "ForumGroupTemplate", value.ToString())
            End Set
        End Property

        Public Property ForumConfig() As String
            Get
                Return GetStringSetting("ForumConfig", String.Empty)
            End Get
            Set(value As String)
                Settings("ForumConfig") = value
                objModules.UpdateTabModuleSetting(TabModuleId, "ForumConfig", value)
            End Set
        End Property
        Public Property AvatarHeight() As Integer
            Get
                Return GetIntegerSetting(SettingKeys.AvatarHeight, 48)
            End Get
            Set(value As Integer)
                Settings(SettingKeys.AvatarHeight) = value.ToString()
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.AvatarHeight, value.ToString())
            End Set
        End Property
        Public Property AvatarWidth() As Integer
            Get
                Return GetIntegerSetting(SettingKeys.AvatarWidth, 48)
            End Get
            Set(value As Integer)
                Settings(SettingKeys.AvatarWidth) = value.ToString()
                objModules.UpdateModuleSetting(ModuleId, SettingKeys.AvatarWidth, value.ToString())
            End Set
        End Property
        Public Function GetIntegerSetting(key As String, defaultValue As Integer) As Integer
            If Settings.ContainsKey(key) Then
                If IsNumeric(Settings(key)) Then
                    Return Convert.ToInt32(Settings(key).ToString())
                Else
                    Return defaultValue
                End If
            Else
                Return defaultValue
            End If
        End Function
        Public Function GetBooleanSetting(key As String, defaultValue As Boolean) As Boolean
            If Settings.ContainsKey(key) Then
                Return Convert.ToBoolean(Settings(key).ToString())
            Else
                Return defaultValue
            End If
        End Function
        Public Function GetStringSetting(key As String, defaultValue As String) As String
            If Settings.ContainsKey(key) Then
                Return Settings(key).ToString()
            Else
                Return defaultValue
            End If
        End Function
    End Class
End Namespace

